#include "Camera.h"
#include "Direct3D.h"
#include "TextureManager.h"
#include "../World/Entity/ObjectInterface.h"

Camera2D::Camera2D(void)
{
	m_CameraX = 0;
	m_CameraY = 0;
	m_CameraWidth = 0;
	m_CameraHeight = 0;
	m_D3D = NULL;
	m_TM = NULL;
}

Camera2D::~Camera2D(void)
{
	m_CameraX = 0;
	m_CameraY = 0;
	m_CameraWidth = 0;
	m_CameraHeight = 0;
	m_D3D = NULL;
	m_TM = NULL;
}

void Camera2D::CreateCamera(double x, double y, double width, double height)
{
	m_CameraX = x;
	m_CameraY = y;
	m_CameraWidth = width;
	m_CameraHeight = height;
}

void Camera2D::Update(void)
{
	if( m_Target )
	{
		m_CameraX = m_Target->GetX()-(m_CameraWidth/2);
		m_CameraY = m_Target->GetY()-(m_CameraHeight/2);
	}
}

bool Camera2D::Draw(int id, int x, int y, float xScale, float yScale, RECT* pSection, float rotCenterX, float rotCenterY, float rotation, DWORD color)
{
	x = (int)GetLocalX(x);
	y = (int)GetLocalY(y);

	return m_TM->Draw(id, x, y, xScale, yScale, pSection, rotCenterX, rotCenterY, rotation, color);
}

void Camera2D::TranslateCamera(double x, double y)
{
	m_CameraX += x;
	m_CameraY += y;
}

// Accessors
double Camera2D::GetWidth(void)
{
	return m_CameraWidth;
}

double Camera2D::GetHeight(void)
{
	return m_CameraHeight;
}

double Camera2D::GetX(void)
{
	return m_CameraX;
}

double Camera2D::GetY(void)
{
	return m_CameraY;
}

double Camera2D::GetLocalX(double x)
{
	return x - m_CameraX;
}

double Camera2D::GetLocalY(double y)
{
	return y - m_CameraY;
}

// Mutators
void Camera2D::SetWidth(double width)
{
	m_CameraWidth = width;
}

void Camera2D::SetHeight(double height)
{
	m_CameraHeight = height;
}

void Camera2D::SetX(double x)
{
	m_CameraX = x;
}

void Camera2D::SetY(double y)
{
	m_CameraY = y;
}

void Camera2D::SetD3D(Direct3D* d3d)
{
	m_D3D = d3d;
}

void Camera2D::SetTextureManager(TextureManager* textureManager)
{
	m_TM = textureManager;
}

void Camera2D::SetTarget(ObjectInterface* target)
{
	m_Target = target;
}